<?php

namespace Application\Model;

use Application\Model\Entity\Country;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Select;

class CountryModel extends AbstractTableGateway {
	protected $table = 'tb_country';

	public function __construct(Adapter $adapter) {
		$this->adapter = $adapter;
	}

	public function fetchAll() {
		$resultSet = $this->select();

		$countries = array();
		foreach($resultSet as $set) {
			$countries[] = new Country((array) $set);
		}
		return $countries;
	}

	public function fetchSelectOptions() {
		$countries = $this->fetchAll();
		$options = array();
		foreach($countries as $country) {
			$options[] = array (
	            'value' => $country->getId(),
	            'label' => $country->getName(),
			);
		}
		return $options;
	}
}